package de.fuberlin.inf.dbs.ue07;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author khahn
 *
 */
public class BaseDAO {
	
	private static final String URL_DATABASE = "jdbc:oracle:thin:@esel.mi.fu-berlin.de:1521:agdb";
	private static final String CLASS_NAME = "oracle.jdbc.driver.OracleDriver";
	
	/**
	 * establishes a connection to the database with given user and pw
	 * @param user
	 * @param pw
	 * @return connection to database according to URL and CLASS_NAME, 
	 * null if connection cannot be established
	 * 
	 */
	public static Connection getConnection(String user, String pw) {
		Connection conn = null;
		try {
			Class.forName(CLASS_NAME);
			conn = DriverManager.getConnection(URL_DATABASE, user, pw);
		} catch (Exception e) {
			e.printStackTrace();
		}	
		return conn;
	}
	
	/**
	 * closes the given connection
	 * @param conn
	 */
	public static void closeConnection(Connection conn) {
		try {
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}